//货柜管理-换货申请
App.util.ns('Admin.Apply.Exchange');
Admin.Apply.Exchange.ExchangeApply = function(dataTable){
    var win = new App.Win({
        name: 'exchange_apply',
        title: '换货申请',
        width: '720px'
    });
    //列表
    win.dataTable = new App.DataTable({
        baseUrl: '/admin/cabinet/cell',
        dataUrl: 'lists',
        table: {
            id: 'id',
            main: 1,
            showId: false,
            withSelect: false,
            columns: [
                {name: '位置', width: '90px', value: function(item){
                    return item.row + ' 行，' + item.col + ' 列';  
                }},
                {name: '原商品', value: function(item){
                    var name = item.goods ? item.goods.name : '未分配';
                    return $('<span style="margin: 0 6px">'+name+'</span>');
                }},
                {name: '期望商品', width: '350px', value: function(item){
                    var selector = new App.Form.SelectLists({
                        type: 'selectLists', 
                        name: 'id', 
                        title: '期望商品', 
                        data_id: 'goods_id', 
                        width: '600px',
                        data_name: function(item){
                            return item.id+': '+item.name;
                        },
                        dataTable: {
                            baseUrl: '/client/apply/exchange/goods',
                            dataUrl: 'lists',
                            data_id: 'id',
                            data_name: 'name',
                            table: {
                                id: 'id',
                                main: 0,
                                columns: [
                                    {name: '商品名', value: 'name'}
                                ]
                            },
                            filter: [
                                {type: 'keywords'}
                            ]
                        },
                        detail: {
                            form: {
                                items: App.util.copy(Admin.Goods.Goods.Conf.form)
                            }
                        }
                    });
                    selector.dataTable.win.fix(win.frame);
                    if(selector.detail){
                        selector.detail.win.fix(win.frame);
                    }
                    if(item.target){
                        selector.change(item.target.id, item.target.name, item.target);
                    }
                    selector.view();
                    return selector.frame;
                }}
            ]
        },
        after: function(self){
            self.frame.find('> .header').remove();
            self.frame.find('.data-table').addClass('table-bordered').removeClass('table-hover');
            self.fix(win.contentContainer);
        }
    });
    win.change = function(cabinet, info){
        win.setTitle('换货申请 - '+cabinet.name);
        var data = JSON.parse(info);
        win.dataTable.table.flushItmes(data);
        win.dataTable.frame.find('tbody td').css({padding: '0'});
        return win;
    };
    win.hide();
    return win;
};